// pages/liveRoom/liveRoom.js
var util = require('../../../utils/util')   //引入配置公共请求接口
import { livingList, replayList } from '../../../config/config'
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    livingData: [], // 正在直播列表
    replayData: [], // 历史直播列表
    formatTime: app.globalData.formatTime,
    statusHeight: app.globalData.StatusBar
  },

  /**
   * 生命周期函数--监听页面加载
   */
  setNavHeight(){
    const sysInfo = wx.getSystemInfoSync()
    const statusHeight = sysInfo.statusBarHeight
    this.setData({
      statusHeight
    })
  },
  onLoad: function (options) {
    this.setNavHeight() 
    this.getData()
  },
  getScroll(e) { //监听滑动
    var scorll = e.detail.scrollTop
    if (scorll > 50 && scorll < 150) {
      this.setData({
        returnBoxgo: 'returnBoxgo'
      });
    } else if (scorll > 150) {
      this.setData({
        returnBoxgo: 'returnBoxgo',
      });
    } else if (scorll < 50) {
      this.setData({
        returnBoxgo: '',
      });
    }
  },
  getData() {
    app.reqFun.requestJson('get', livingList, '', (res) => {
      if (res.data.success == 1) {
        let data = res.data.data
        for(var i = 0; i < data.length; i++) {
          data[i].start_time = this.data.formatTime(data[i].start_time)
        }
        this.setData({
          livingData: data
        })
      }
    })
    app.reqFun.requestJson('get', replayList, '', (res) => {
      if (res.data.success == 1) {
        this.setData({
          replayData: res.data.data
        })
      }
    })
  },
  lrDetail(item) {
      let roomId = item.currentTarget.dataset.item.roomid
      let customParams = encodeURIComponent(JSON.stringify({ path: '/packageLive/pages/liveRoomDetail/liveRoomDetail', pid: 1 }))
      wx.navigateTo({
        url: `plugin-private://wx2b03c6e691cd7370/pages/live-player-plugin?room_id=${roomId}&custom_params=${customParams}`
    })
  },
  goreBack: function (e) { //返回
    wx.navigateBack({
      delta: 1
    })
  },
  goHome: function (e) { //返回主页
    wx.reLaunch({
      url: '/pages/newIndex/newIndex'
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})